﻿
@{
    ViewBag.Title = "我购买的商品";
    Layout = "~/Views/Shared/_MallLayout.cshtml";
}

<body class="page-order release-order mescroll" id="mescroll">
    <div class="mod-type mod-typeTab mb20">
        <ul>
            <li class="cur" value="-1">
                全部
                <i></i>
            </li>
            <li value="0">待发货<i></i></li>
            <li value="1">待收货<i></i></li>
            <li value="3">交易取消<i></i></li>
            <li value="2">交易完成<i></i></li>
        </ul>
    </div>
    <div class="mod-order lt-mb">
        <ul id="dataList"></ul>
    </div>
    <link href="~/Scripts/mescroll/mescroll.min.css" rel="stylesheet" />
    <script src="~/Scripts/mescroll/mescroll.min.js"></script>
    <script>
        $(function () {
            var status = -1;
            var mescroll = new MeScroll("mescroll", {
                down: {
                    auto: false,
                    callback: function (mescroll) {
                        mescroll.resetUpScroll(); //下拉刷新的回调,默认重置上拉加载列表为第一页
                    },
                },
                up: {
                    callback: getListData,
                    clearEmptyId: "dataList",
                    isBounce: false,
                    noMoreSize: 3,
                    htmlNodata: '<p class="upwarp-nodata">--没有更多数据了 --</p >',
                    empty: {
                        warpId: "dataList",
                        icon: "",
                        tip: "亲,没有您要找的商品~",

                    },
                    toTop: {
                        //src: "/content/c2c/img/toup.png",
                        //html: "<p>^<br/>顶部<p>",
                        //offset: 500
                    }
                }
            });
            function getListData(page) {
                $.ajax({
                    type: 'post',
                    url: '/BazaarOrder/_BuyOrder',
                    data: { page: page.num, size: page.size, status: status },
                    success: function (response) {
                        var paged = $(response).siblings("page");
                        var rows = Number.parseInt(paged.attr("rows"));
                        var total = Number.parseInt(paged.attr("total_result"));
                        mescroll.endBySize(rows, total);
                        if (paged.length == 1) {

                            $("#dataList").append($(response));
                            $('#dataList page').remove();
                        }

                    },
                    error: function (e) {
                        //联网失败的回调,隐藏下拉刷新和上拉加载的状态
                        mescroll.endErr();
                    }
                });
            }
            var flag = false;
            //删除
            $("#dataList").delegate(".btn_del", "click", function (e) {
                layer.load(1);
                var id = $(this).attr("data-id");
                if (flag) return;
                flag = true;
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/BazaarOrder/BuyDelete",//url
                    data: { id: id },
                    success: function (result) {
                        layer.closeAll('loading');
                        if (result.result_code == 1000) {
                            layer.msg(result.result_msg);
                            location.reload();
                        }
                        else {
                            layer.msg(result.result_msg);
                        }
                        flag = false;
                    },
                    error: function () {
                        layer.msg("异常！");
                        flag = false;
                    }
                });
            });
            //收货
            $("#dataList").delegate(".btn_receive", "click", function (e) {
                var id = $(this).attr("data-id");
                layer.confirm('您确定要收货么？', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    layer.load(1);
                   
                    if (flag) return;
                    flag = true;
                    $.ajax({
                        //几个参数需要注意一下
                        type: "POST",//方法类型
                        dataType: "json",//预期服务器返回的数据类型
                        url: "/BazaarOrder/Receive",//url
                        data: { id: id },
                        success: function (result) {
                            layer.closeAll('loading');
                            if (result.result_code == 1000) {
                                layer.msg(result.result_msg);
                                location.reload();
                            }
                            else {
                                layer.msg(result.result_msg);
                            }
                            flag = false;
                        },
                        error: function () {
                            layer.msg("异常！");
                            flag = false;
                        }
                    });
                }, function () {
                    
                });
               
            });
            $(".mod-typeTab li").click(function () {
                $(this).addClass('cur').siblings().removeClass('cur');
                status = $(this).val();
                mescroll.resetUpScroll();
                mescroll.hideTopBtn();
            });
        })
    </script>
</body>

